//
//  HomeBannerCollectionViewCell.swift
//  XMYouPin
//
//  Created by 王宗成 on 2019/7/4.
//  Copyright © 2019 王宗成. All rights reserved.
//

import UIKit
import FSPagerView
import Kingfisher
class HomeBannerTableViewCell: WZC_TableViewCell {
    
    var model:HomeFloorModel?{
        
        didSet
        {
            self.pagerView.reloadData()
        }
    }
    
    private lazy var pagerView : FSPagerView = {
        
        let pagerView = FSPagerView()
        pagerView.delegate = self
        pagerView.dataSource = self
        pagerView.automaticSlidingInterval =  3
        pagerView.isInfinite = true
        pagerView.interitemSpacing = 15
        pagerView.transformer = FSPagerViewTransformer(type: .crossFading)
        pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell")
        self.addSubview(pagerView)
        return pagerView
    }()
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
         setupLayOut()
    }
    

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupLayOut() {
        // 分页轮播图
        
        let rate:CGFloat =  1080.0/450.0
      
        self.pagerView.itemSize = CGSize.init(width: kScreenW, height: kScreenW/rate)
        self.pagerView.frame = CGRect(x: 0, y: 0, width: kScreenW, height: kScreenW/rate)
    }
}


extension HomeBannerTableViewCell:FSPagerViewDelegate,FSPagerViewDataSource
{

    func numberOfItems(in pagerView: FSPagerView) -> Int {
        return self.model?.data?.items.count ?? 0
    }
    func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell {
        let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index)
        cell.imageView?.kf.setImage(with: URL(string: self.model?.data?.items[index].item?.pic_url ?? ""))
        return cell
    }
   
}
